﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace Light.Framework
{
    /// <summary>
    /// 数据库字段映射特性
    /// </summary>
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Enum | AttributeTargets.Property)]
    public class ColumnAttribute : Attribute
    {
        /// <summary>
        /// 数据库列名
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 数据库类型
        /// </summary>
        public DbType Type { get; set; }

        /// <summary>
        /// 长度
        /// </summary>
        public int Size { get; set; }

        /// <summary>
        /// 被其他类引用时，级别查询的深度,
        /// 避免构建太臃肿的查询结果列，默认1，
        /// 如引用了User 类型的对象obj,则 obj.User.Name 可查询
        /// 如引用了需要取obj.User.User.Name 需设置为 2
        /// </summary>
        public int Casade { get; set; }

        /// <summary>
        /// 是否只用于查询，不保存此值
        /// </summary>
        public bool ReadOnly { get; set; }

        /// <summary>
        /// 是否为自增列
        /// </summary>
        public bool IsAutoIncrement { get; set; }

        /// <summary>
        /// 构造函数：列名和属性名一致的时候用
        /// </summary>
        public ColumnAttribute()
        {
            Casade = 2;
        }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="name">数据库列名</param>
        public ColumnAttribute(string name)
            : this()
        {
            Name = name;
        }
    }
}
